import http from "../tools/http";

const {ccclass, property} = cc._decorator;

@ccclass
export default class qxc_tools {
    //获取UUID
    static generateUUID() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
          var r = Math.random() * 16 | 0,
              v = c === 'x' ? r : (r & 0x3 | 0x8);
          return v.toString(16);
        });
    }
    //获取随机数
    public static ranNumber(min: number, max: number): number {
        return Math.floor(Math.random() * (max - min)) + min;
    }
    
    //把图片设成灰度
    public static setSpriteGrey(sprite:cc.Sprite){
        sprite.setMaterial(0,cc.Material.getBuiltinMaterial("2d-gray-sprite"));
    }
    //把node上的图片设成灰度
    public static setNodeSpriteGrey(node:cc.Node){
        node.getComponent(cc.Sprite).setMaterial(0,cc.Material.getBuiltinMaterial("2d-gray-sprite"));
    }
    //
    public static loadDataU(url:string, path: string, data:any = {}): Promise<{}> {//获取离线收益数值
        return new Promise((resolve, reject) => {
            http.GET_url(
                url,
                path,
                data,
                (c: object) => {
                    resolve(c);
                },
                (e: object) => {
                    reject(e);
                });
        })
    }
}


